package me.jollyfly.jshop.content.server.service.impl

import me.jollyfly.jshop.content.client.constant.ContentCodeConstant
import me.jollyfly.jshop.content.client.model.ContentDO
import me.jollyfly.jshop.content.server.dao.ContentCatDAO
import me.jollyfly.jshop.content.server.dao.ContentDAO
import me.jollyfly.jshop.content.server.service.ContentService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional


@Service
open class ContentServiceImpl : ContentService{





    @Autowired
    private var contentDAO: ContentDAO? = null

    @Autowired
    private var contentCatDAO: ContentCatDAO? = null


    @Transactional(readOnly = true, rollbackFor = [(Exception::class)])
    override fun listSliders(): List<ContentDO> {
        val contentCat =  contentCatDAO!!.getContentCatByCode(ContentCodeConstant.INDEX_AD_SLIDER)
        val content = ContentDO()
        content.categoryId = contentCat.id
        return contentDAO!!.select(content).sortedBy { it.sortOrder }
    }

    @Transactional(readOnly = true,rollbackFor = [(Exception::class)])
    override fun listRecommendation(): List<ContentDO> {
        val contentCat =  contentCatDAO!!.getContentCatByCode(ContentCodeConstant.INDEX_AD_RECOMMENDATION)
        val content = ContentDO()
        content.categoryId = contentCat.id
        return contentDAO!!.select(content).sortedBy { it.sortOrder }
    }

}